﻿using Lifebucket.CommandProcessor.Command;
using Lifebucket.Domain.Commands;
using Lifebucket.Data.Repositories;
using Lifebucket.Data.Infrastructure;

namespace Lifebucket.Domain.Handlers
{
    public class DeleteBucketItemHandler : ICommandHandler<DeleteBucketItemCommand>
    {
        private readonly IBucketItemRepository bucketItemRepository;
        private readonly IUnitOfWork unitOfWork;
        public DeleteBucketItemHandler(IBucketItemRepository bucketItemRepository, IUnitOfWork unitOfWork)
        {
            this.bucketItemRepository = bucketItemRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(DeleteBucketItemCommand command)
        {
            var bucketItem = bucketItemRepository.GetById(command.BucketItemId);
            bucketItemRepository.Delete(bucketItem);
            unitOfWork.Commit();
            return new CommandResult(true);
        }
    }
}
